package com.seafood.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.List;

/**
 * 产品实体类
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "products")
public class Product extends BaseEntity {
    
    @NotBlank(message = "产品名称不能为空")
    @Size(max = 200, message = "产品名称长度不能超过200字符")
    @Column(nullable = false, length = 200)
    private String name;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "category_id")
    private Category category;
    
    @Lob
    private String description;
    
    @Column(length = 100)
    private String origin;
    
    @Column(length = 100)
    private String species;
    
    @Column(name = "processing_method", length = 100)
    private String processingMethod;
    
    @Column(length = 50)
    private String grade;
    
    @DecimalMin(value = "0.0", message = "价格不能小于0")
    @Column(precision = 10, scale = 2)
    private BigDecimal price;
    
    @Column(name = "stock_quantity")
    private Integer stockQuantity = 0;
    
    @Column(length = 20)
    private String unit = "公斤";
    
    @Column(name = "weight_per_unit", precision = 8, scale = 3)
    private BigDecimal weightPerUnit;
    
    @Column(name = "image_url", length = 500)
    private String imageUrl;
    
    @Lob
    private String images; // JSON格式存储多图
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private ProductStatus status = ProductStatus.ACTIVE;
    
    // 订单详情
    @OneToMany(mappedBy = "product", fetch = FetchType.LAZY)
    private List<OrderItem> orderItems;
    
    // 溯源信息
    @OneToMany(mappedBy = "product", fetch = FetchType.LAZY)
    private List<Traceability> traceabilityList;
    
    // 购物车项
    @OneToMany(mappedBy = "product", fetch = FetchType.LAZY)
    private List<ShoppingCart> shoppingCarts;
    
    /**
     * 产品状态枚举
     */
    public enum ProductStatus {
        ACTIVE,         // 上架
        INACTIVE,       // 下架
        OUT_OF_STOCK    // 缺货
    }
}